//主文件
(function(w){
    var inviteRd = function(){
        this.init();
        return this;
    }, c,userId = "";

    inviteRd.prototype = {
        init: function(){
            c = this;
            $("#middle_img").height($("body").height() - 112);

            userId = getQueryString("userObjId");
            c.data = {"url":"/rest/v1.0/mobile/web/getAppUserShare/"+userId,native: false};
            netWork(c.data,c.initData);
        },
        initData: function(data){
            var pData = {communityId:data.data.communityId.objId};
            c.data = {"url":"/rest/v1.0/mobile/shares/getCommunityReward",native: false,method:"post",data:pData};
            netWork(c.data,function(){

            });
        },
        phoneJudge: function(data){
            if(data.result.status == 1){
                c.displayTip();
                $("#invite_phone").text($("#phone").val());
                $(".done-title").css("display","block");
                $(".done-content").css("display","block");
                $(".already-content").css("display","none");
            }else if(data.result.status == 2){
                tip.toast("该手机号码已被注册！");
            }else if(data.result.status == 3){
                c.displayTip();
                $(".done-title").css("display","none");
                $(".done-content").css("display","none");
                $(".already-content").css("display","block");
            }
        },
        displayTip: function(){
            $("#mask").css("display","block");
            $("#join_success").css("display","block");
            $("#join_success").css("margin-top",-$("#join_success").height()/2 + "px");
        },
        evt: function(){
            $("#activation").on("click",function(){
                if ($("#phone").val() == "") return tip.toast("请输入手机号");
                if (!/^[1][3-9][0-9]{9,9}$/.test($("#phone").val())) {
                            return tip.toast("请填写正确的手机号码");
                }
                var postData = {userId:userId,code:"12323",phone:$("#phone").val()};
                c.data = {"url":"/rest/v1.0/mobile/shares/addInvitationShare",native: false,method: "post",data:postData};
                netWork(c.data,c.phoneJudge);
            });
            $("#close_button").on("click",function(){
                $("#join_success").css("display","none");
                $("#mask").css("display","none");
            });
            $("#join_success,#mask").on("touchmove",function(e){
                e.preventDefault();
            });
            $(".start-loading").css("display","none");
        }
    };

    w.inviteRd = inviteRd;
}(window));
var inviteReward = new inviteRd();
inviteReward.evt(inviteReward);